﻿Ext.define('MyDesktop.frgbak', {
    extend: 'Ext.ux.desktop.Module',
	requires: [
        'Ext.grid.*',
		'Ext.data.*',
		'Ext.util.*',
		'Ext.ux.grid.FiltersFeature',
		'Ext.toolbar.Paging',
		'Ext.ux.PreviewPlugin',
		'Ext.ux.SlidingPager'
    ],
    id:'frgbak-win',
	myself:true,
	today:true,
	frgbaktype:'all',
	status:'all',
	init : function(){
        this.launcher = {
            text: '富人国备份',
            iconCls:'icon-grid',
            handler : this.createWindow,
            scope: this
        };
    },
	createWindow : function(){
		var me = this;
		var desktop = this.app.getDesktop();
        var win = desktop.getWindow('frgbak-win');
		var groupingFeature = Ext.create('Ext.grid.feature.Grouping',{
			groupHeaderTpl: '{name}',
            groupByText:'使用此列分组',
            showGroupsText:'分组',
		});
		if (!Ext.ModelManager.isRegistered('FRG_BAK_model')){
			Ext.define('FRG_BAK_model', {
				extend: 'Ext.data.Model',
				idProperty:'id',
				fields: [
						 {name: 'id', type: 'string'},
						 {name: 'lang', type: 'string'},
						 {name: 'partner', type: 'string'},
						 {name: 'server',  type: 'string'},
						 {name: 'filename',  type: 'string'},
						 {name: 'task_start_time',  type: 'string'},
						 {name: 'process_start_time',  type: 'string'},
						 {name: 'dump_start_time',  type: 'string'},
						 {name: 'dump_end_time',  type: 'string'},
						 {name: 'zip_start_time',  type: 'string'},
						 {name: 'zip_end_time',  type: 'string'},
						 {name: 'transport_start_time',  type: 'string'},
						 {name: 'transport_end_time',  type: 'string'},
						 {name: 'end_time',  type: 'string'},
						 {name: 'unzip_size',  type: 'string'},
						 {name: 'zip_size',  type: 'string'},
						 {name: 'log',  type: 'string'},
						 {name: 'status',  type: 'string'}
				]
			});
		}
		Ext.create('Ext.data.Store',{
			storeId:'FRG_BAK_Store',
			model: 'FRG_BAK_model',
			autoSync: true,
			buffered: true,
			purgePageCount: 0,
			loadMask: false,
			proxy: {
				type: 'ajax',
				url : '/interface.php',
				reader: {
					type: 'json',
					root: 'frg_bak_list',
					idProperty: 'id',
					totalProperty: 'total'
				},
				extraParams:{
					type: 'frg_bak_list',
					myself:me.myself,
					today:me.today,
					frgbaktype:me.frgbaktype,
					status:me.status
				}
			},
			pageSize: 20,
            groupField: 'partner',
            sorters: ['partner','server'],
            remoteSort:true,
            remoteGroup:false
		});
		
		if (!win){
			win = desktop.createWindow({
                id: 'frgbak-win',
                title:'富人国备份',
				autoDestroy:true,
                width:740,
                height:480,
                iconCls: 'icon-grid',
                animCollapse:false,
                constrainHeader:true,
                layout: 'fit',
                items: [{
					xtype: 'gridpanel',
					id: 'frgbak-grid',
					autoDestroy:true,
					iconCls: 'icon-grid',
					border:0,
					frame: false,
					store: 'FRG_BAK_Store',
					//columnLines: true,
					invalidateScrollerOnRefresh: false,
					viewConfig: {
						id: 'frgbak-grid-preview',
						trackOver: false,
						stripeRows: false,
						plugins: [{
							ptype: 'preview',
							bodyField: 'log',
							expanded: true,
							pluginId: 'preview'
						}]
					},
					defaults: {
						sortable : true
					},
					columns: [{
							text: '序号',
							flex: 1,
							hidden: true,
							dataIndex: 'id'
					},{
							text: '语言',
							flex: 1,
							dataIndex: 'lang'
					},{
							text: '合作方',
							flex: 1,
							dataIndex: 'partner'
					},{
							text: '游戏服',
							flex: 1,
							dataIndex: 'server'
					},{
							text: '文件名',
							flex: 1,
							hidden: true,
							dataIndex: 'filename'
					},{
							text: '任务开始时间',
							flex: 1,
							hidden: true,
							dataIndex: 'task_start_time'
					},{
							text: '备份进程开始时间',
							flex: 1,
							hidden: true,
							dataIndex: 'process_start_time'
					},{
							text: '数据库导出开始时间',
							flex: 1,
							hidden: true,
							dataIndex: 'dump_start_time'
					},{
							text: '数据库导出结束时间',
							flex: 1,
							hidden: true,
							dataIndex: 'dump_end_time'
					},{
							text: '文件压缩开始时间',
							flex: 1,
							hidden: true,
							dataIndex: 'zip_start_time'
					},{
							text: '文件压缩结束时间',
							flex: 1,
							hidden: true,
							dataIndex: 'zip_end_time'
					},{
							text: '文件远程传输开始时间',
							flex: 1,
							hidden: true,
							dataIndex: 'transport_start_time'
					},{
							text: '文件远程传输结束时间',
							flex: 1,
							hidden: true,
							dataIndex: 'transport_end_time'
					},{
							text: '任务结束时间',
							flex: 1,
							hidden: true,
							dataIndex: 'end_time'
					},{
							text: '文件压缩前大小',
							flex: 1,
							hidden: true,
							dataIndex: 'unzip_size'
					},{
							text: '文件压缩后大小',
							flex: 1,
							hidden: true,
							dataIndex: 'zip_size'
					},{
							text: '状态',
							flex: 1,
							dataIndex: 'status',
							renderer:function(value, meta, rec, row, col, store,view){
                                var id = me.generateid(rec);
                                if (value == '1'){
                                    Ext.Function.defer(function(){
                                        new Ext.ProgressBar({
                                            id:id,
                                            autoRender:true,
                                            renderTo: id,
                                            text:'任务开始...',
                                            value: 0
                                        });
                                    }, 100);
                                }else if (value == '2'){
                                    Ext.Function.defer(function(){
                                        new Ext.ProgressBar({
                                            id:id,
                                            autoRender:true,
                                            renderTo: id,
                                            text:'进程开始...',
                                            value: 0.05
                                        });
                                    }, 100);
                                }else if (value == '3'){
                                    Ext.Function.defer(function(){
                                        new Ext.ProgressBar({
                                            id:id,
                                            autoRender:true,
                                            renderTo: id,
                                            text:'数据库导出...',
                                            value: 0.1
                                        });
                                    }, 100);
                                }else if (value == '4'){
                                    Ext.Function.defer(function(){
                                        new Ext.ProgressBar({
                                            id:id,
                                            autoRender:true,
                                            renderTo: id,
                                            text:'备份文件压缩...',
                                            value: 0.4
                                        });
                                    }, 100);
                                }else if (value == '5'){
                                    Ext.Function.defer(function(){
                                        new Ext.ProgressBar({
                                            id:id,
                                            autoRender:true,
                                            renderTo: id,
                                            text:'备份文件传输...',
                                            value: 0.7,
											cls:'transport_progress-bar'
                                        });
                                    }, 100);
                                }else if (value == '6'){
                                    Ext.Function.defer(function(){
                                        new Ext.ProgressBar({
                                            id:id,
                                            autoRender:true,
                                            renderTo: id,
                                            text:'备份完毕！！',
                                            value: 1,
											cls:'finish_progress-bar'
                                        });
                                    }, 100);
                                }else if (value == '255'){
                                    Ext.Function.defer(function(){
                                        new Ext.ProgressBar({
                                            id:id,
                                            autoRender:true,
                                            renderTo: id,
                                            text:'备份错误！！',
                                            value: 1,
											cls:'error_progress-bar'
                                        });
                                    }, 100);
                                }
                                return '<span id="' + id + '"></span>';
                            }
                            
					}],
					bbar: Ext.create('Ext.PagingToolbar', {
						pageSize: 10,
						store: 'FRG_BAK_Store',
						displayInfo: false,
						plugins: Ext.create('Ext.ux.SlidingPager', {}),
						items:[
							'->', {
							text: '显示日志',
							pressed: true,
							enableToggle: true,
							toggleHandler: function(btn, pressed) {
								var preview = Ext.getCmp('frgbak-grid-preview').getPlugin('preview');
								preview.toggleExpanded(pressed);
							}
						}]
					}),
					tbar: [{
						xtype: 'buttongroup',
						columns: 2,
						title: '查询设置',
						items: [{
							xtype: 'button',
							id:'frgbak_myself',
							text: '只显示自己',
							scale: 'medium',
							iconCls: 'frgbak_my',
							iconAlign:'left',
							enableToggle:true,
							toggleHandler:function(button,state){
								if(state){
                                    Ext.getStore('FRG_BAK_Store').proxy.extraParams.myself=true;
                                    Ext.getCmp('frgbak_alluser').toggle(false);
                                    Ext.getStore('FRG_BAK_Store').load();
                                }
							}
						},{
							xtype: 'button',
							id:'frgbak_alluser',
							text: '显示全部用户',
							scale: 'medium',
							iconCls: 'frgbak_people',
							iconAlign:'left',
							enableToggle:true,
							toggleHandler:function(button,state){
								if(state){
                                    Ext.getStore('FRG_BAK_Store').proxy.extraParams.myself=false;
                                    Ext.getCmp('frgbak_myself').toggle(false);
                                    Ext.getStore('FRG_BAK_Store').load();
                                }
							}
						},{
							xtype: 'button',
							id:'frgbak_today',
							text: '只显示今天',
							scale: 'medium',
							iconCls: 'frgbak_today',
							iconAlign:'left',
							enableToggle:true,
							toggleHandler:function(button,state){
                                if(state){
                                    Ext.getStore('FRG_BAK_Store').proxy.extraParams.today=true;
                                    Ext.getCmp('frgbak_history').toggle(false);
                                    Ext.getStore('FRG_BAK_Store').load();
                                }
							}
						},{
							xtype: 'button',
							id:'frgbak_history',
							text: '显示历史',
							scale: 'medium',
							iconCls: 'frgbak_history',
							iconAlign:'left',
							enableToggle:true,
							toggleHandler:function(button,state){
                                if(state){
                                    Ext.getStore('FRG_BAK_Store').proxy.extraParams.today=false;
                                    Ext.getCmp('frgbak_today').toggle(false);
                                    Ext.getStore('FRG_BAK_Store').load();
                                }
							}
						}]
					},{
						xtype: 'buttongroup',
						columns: 2,
						title: '备份类型',
						items: [{
							xtype: 'button',
							id:'frgbak_all',
							text: '显示全部',
							iconCls: 'frgbak_all',
							iconAlign:'top',
							scale: 'large',
							rowspan:3,
							enableToggle:true,
							toggleHandler:function(button,state){
								if(state){
                                    Ext.getStore('FRG_BAK_Store').proxy.extraParams.frgbaktype = 'all';
                                    Ext.getCmp('frgbak_auto').toggle(false);
                                    Ext.getCmp('frgbak_man').toggle(false);
                                    Ext.getStore('FRG_BAK_Store').load();
                                }
							}
						},{
							xtype: 'button',
							id:'frgbak_auto',
							text: '只显示定时备份',
							scale: 'medium',
							iconCls: 'frgbak_auto',
							iconAlign:'left',
							enableToggle:true,
							toggleHandler:function(button,state){
                                if(state){
                                    Ext.getStore('FRG_BAK_Store').proxy.extraParams.frgbaktype = 'auto';
                                    Ext.getCmp('frgbak_all').toggle(false);
                                    Ext.getCmp('frgbak_man').toggle(false);
                                    Ext.getStore('FRG_BAK_Store').load();
                                }
							}
						},{
							xtype: 'button',
							id:'frgbak_man',
							text: '只显示维护备份',
							scale: 'medium',
							iconCls: 'frgbak_man',
							iconAlign:'left',
							enableToggle:true,
							toggleHandler:function(button,state){
                                if(state){
                                    Ext.getStore('FRG_BAK_Store').proxy.extraParams.frgbaktype = 'man';
                                    Ext.getCmp('frgbak_all').toggle(false);
                                    Ext.getCmp('frgbak_auto').toggle(false);
                                    Ext.getStore('FRG_BAK_Store').load();
                                }
							}
						}]
					},{
						xtype: 'buttongroup',
						columns: 2,
						height:87,
						title: '备份状态',
						items: [{
							xtype: 'splitbutton',
							id:'frgbak_status',
							iconCls: 'frgbak_status',
							iconAlign:'top',
							text: '全部状态',
							scale: 'large',
							rowspan: 3,
							//enableToggle:true,
							handler:function(button,state){
								if(Ext.getStore('FRG_BAK_Store').proxy.extraParams.status == 'all'){
									Ext.getStore('FRG_BAK_Store').proxy.extraParams.status = 1;
									button.setText('任务开始');
									//button.toggle(true);
									Ext.getStore('FRG_BAK_Store').load();
									return;
								}else if(Ext.getStore('FRG_BAK_Store').proxy.extraParams.status == 1){
									Ext.getStore('FRG_BAK_Store').proxy.extraParams.status = 2;
									button.setText('进程开始');
									//button.toggle(true);
									Ext.getStore('FRG_BAK_Store').load();
									return;
								}else if(Ext.getStore('FRG_BAK_Store').proxy.extraParams.status == 2){
									Ext.getStore('FRG_BAK_Store').proxy.extraParams.status = 3;
									button.setText('数据库导出');
									//button.toggle(true);
									Ext.getStore('FRG_BAK_Store').load();
									return;
								}else if(Ext.getStore('FRG_BAK_Store').proxy.extraParams.status == 3){
									Ext.getStore('FRG_BAK_Store').proxy.extraParams.status = 4;
									button.setText('备份文件压缩');
									//button.toggle(true);
									Ext.getStore('FRG_BAK_Store').load();
									return;
								}else if(Ext.getStore('FRG_BAK_Store').proxy.extraParams.status == 4){
									Ext.getStore('FRG_BAK_Store').proxy.extraParams.status = 5;
									button.setText('备份文件传输');
									//button.toggle(true);
									Ext.getStore('FRG_BAK_Store').load();
									return;
								}else if(Ext.getStore('FRG_BAK_Store').proxy.extraParams.status == 5){
									Ext.getStore('FRG_BAK_Store').proxy.extraParams.status = 6;
									button.setText('备份完毕');
									//button.toggle(true);
									Ext.getStore('FRG_BAK_Store').load();
									return;
								}else if(Ext.getStore('FRG_BAK_Store').proxy.extraParams.status == 6){
									Ext.getStore('FRG_BAK_Store').proxy.extraParams.status = 255;
									button.setText('备份错误');
									//button.toggle(true);
									Ext.getStore('FRG_BAK_Store').load();
									return;
								}else if(Ext.getStore('FRG_BAK_Store').proxy.extraParams.status == 255){
									Ext.getStore('FRG_BAK_Store').proxy.extraParams.status = 'all';
									button.setText('全部状态');
									//button.toggle(true);
									Ext.getStore('FRG_BAK_Store').load();
									return;
								}
							},
							menu: [{
							  text: '全部状态',
							  handler:function(){
									Ext.getStore('FRG_BAK_Store').proxy.extraParams.status = 'all';
									Ext.getCmp('frgbak_status').setText('全部状态');
									Ext.getStore('FRG_BAK_Store').load();
							  }
							},{
							  text: '任务开始',
							  handler:function(){
									Ext.getStore('FRG_BAK_Store').proxy.extraParams.status = 1;
									Ext.getCmp('frgbak_status').setText('任务开始');
									Ext.getStore('FRG_BAK_Store').load();
							  }
							},{
							  text: '进程开始',
							  handler:function(){
									Ext.getStore('FRG_BAK_Store').proxy.extraParams.status = 2;
									Ext.getCmp('frgbak_status').setText('进程开始');
									Ext.getStore('FRG_BAK_Store').load();
							  }
							},{
							  text: '数据库导出',
							  handler:function(){
									Ext.getStore('FRG_BAK_Store').proxy.extraParams.status = 3;
									Ext.getCmp('frgbak_status').setText('数据库导出');
									Ext.getStore('FRG_BAK_Store').load();
							  }
							},{
							  text: '备份文件压缩',
							  handler:function(){
									Ext.getStore('FRG_BAK_Store').proxy.extraParams.status = 4;
									Ext.getCmp('frgbak_status').setText('备份文件压缩');
									Ext.getStore('FRG_BAK_Store').load();
							  }
							},{
							  text: '备份文件传输',
							  handler:function(){
									Ext.getStore('FRG_BAK_Store').proxy.extraParams.status = 5;
									Ext.getCmp('frgbak_status').setText('备份文件传输');
									Ext.getStore('FRG_BAK_Store').load();
							  }
							},{
							  text: '备份完毕',
							  handler:function(){
									Ext.getStore('FRG_BAK_Store').proxy.extraParams.status = 6;
									Ext.getCmp('frgbak_status').setText('备份完毕');
									Ext.getStore('FRG_BAK_Store').load();
							  }
							},{
							  text: '备份错误',
							  handler:function(){
									Ext.getStore('FRG_BAK_Store').proxy.extraParams.status = 255;
									Ext.getCmp('frgbak_status').setText('备份错误');
									Ext.getStore('FRG_BAK_Store').load();
							  }
							}]
						}]
					},'->',{
						xtype: 'button',
						id:'frg_bak_new_button',
						text: '增加维护备份',
						scale: 'large',
						//height:87,
						iconCls: 'frgbak_add',
						iconAlign: 'top',
						handler: function() {
							me.create_frgbak_new_Window();
						}
					}],
                    features: [groupingFeature],
					listeners:{
						destroy:function(){
							Ext.TaskManager.stopAll();
						}
						/*selectionchange:function(view,record){
							if (record[0]) {
								Ext.getCmp('FRG_east_attribute').getForm().loadRecord(record[0]);
								Ext.getCmp('east-panel').expand();
							}	
						}*/
					}
				}]
			});
		}
		win.show();
        Ext.getCmp('frgbak_myself').toggle(true);
        Ext.getCmp('frgbak_today').toggle(true);
        Ext.getCmp('frgbak_man').toggle(true);
        Ext.getStore('FRG_BAK_Store').load();
        me.updateProgressBar();
        return win;
	},
	create_frgbak_new_Window:function(){
		var desktop = this.app.getDesktop();
		var frgbak_new = desktop.getWindow('frgbak_new');
		function Tree_Node_Parent_Select(parentNode, checked){
			parentNode.set('checked', checked);
			if (parentNode.isRoot()){
				return
			}else{
				Tree_Node_Parent_Select(parentNode.parentNode,checked);
			}
		}
    	
		function Tree_Node_Children_Select(parentNode, checked){
			parentNode.set('checked', checked);
			Ext.each(parentNode.childNodes, function(childNode, index, allItems){
				childNode.set('checked', checked);
				Tree_Node_Children_Select(childNode, checked);
			});
		}
		if (!Ext.ModelManager.isRegistered('FRG_confirm_model')){
			Ext.define('FRG_confirm_model', {
				extend: 'Ext.data.Model',
				fields: [
					 {name: 'id', type: 'string'},
					 {name: 'lang', type: 'string'},
					 {name: 'partner', type: 'string'},
					 {name: 'server',  type: 'string'}
				]
			});
		}
		Ext.create('Ext.data.Store',{
			storeId:'FRG_confirm_Store',
			autoSync: true,
			buffered:true,
			model: 'FRG_confirm_model',
			remoteSort: false,
			remoteGroup:false,
			loadMask: false,
			groupField: 'partner',
            sorters: ['partner','server'],
			proxy: {
				type: 'memory',
				reader: {
					type: 'json'
				}
			}
		});
		if(!frgbak_new){
			frgbak_new = desktop.createWindow({
				id:'frgbak_new',
				title: '增加维护备份',
				//animateTarget:Ext.getCmp('frg_bak_new_button'),
				closable: true,
				closeAction:'hide',
				width: 600,
				height: 415,
				layout: 'border',
				bodyStyle: 'padding: 5px;',
				items: [{
					region: 'west',
					title: '选择需要备份的服',
					width: 200,
					height:350,
					xtype: 'treepanel',
					id:'FRG_tree',
					split: true,
					collapsible: true,
					store: Ext.create('Ext.data.TreeStore', {
						proxy: {
							type: 'ajax',
							url: '/interface.php?type=frg_bak_tree',
							method: 'POST',
							reader: 'json'
						},
						root: {
							text: '富人国',
							id: 'root',
							expanded: true
						},
						folderSort: true,
						sorters: [{
							property: 'text',
							direction: 'ASC'
						}]
					}),
					useArrows: true,
					autoScroll:true,
					animate:true,
					loadMask: true,
					forceFit:true,
					frame: false,
					rootVisible: false,
					listeners: {  
						itemclick: function(view, record, item, index, e){  
						}, 
						checkchange: function(node, checked){
							node.expand(true,function(){
								Ext.getCmp('FRG_confirm_BAK').getStore().removeAll();
								var Tree_To_Grid = new Array();
								if (node.isLeaf()){
									Tree_Node_Parent_Select(node, checked);
								}else{
									Tree_Node_Children_Select(node, checked);
								}
								Ext.each(Ext.getCmp('FRG_tree').getChecked(), function(node){
									if (node.isLeaf()){
										Tree_To_Grid.push({id:node.get('id'),lang:node.parentNode.parentNode.get('text'),partner:node.parentNode.get('text'),server:node.get('text')});
									}
								});
								Ext.getCmp('FRG_confirm_BAK').getStore().add(Tree_To_Grid);
								Ext.getCmp('FRG_confirm_BAK').getView().refresh();
							});
						}  
					}
				},{
					region: 'center',
					baseCls: 'x-plain',
					items: [{
						xtype:'gridpanel',
						title: '已选游戏服的清单',
						autowidth:true,
						height: 300,								
						autoScroll:true,
						autoShow:true,
						autoRender:true,
						id:'FRG_confirm_BAK',
						iconCls: 'icon-grid',
						frame: true,
						store: 'FRG_confirm_Store',
						columnLines: true,
						//features: [groupingFeature],
						columns: [{
								text: '序号',
								flex: 1,
								hidden: true,
								dataIndex: 'id'
							},{
								text: '语言',
								flex: 1,
								dataIndex: 'lang'
							},{
								text: '合作方',
								flex: 1,
								dataIndex: 'partner'
							},{
								text: '游戏服',
								flex: 1,
								dataIndex: 'server'
							},{
								text: '删除',
								xtype:'actioncolumn', 
								width:25,
								items: [{
									icon: '/resources/themes/images/default/grid/drop-no.gif',
									tooltip: 'Delete',
									handler: function(grid, rowIndex, colIndex) {
										Ext.getCmp('FRG_tree').getStore().getNodeById(grid.getStore().getAt(rowIndex).data.id).set('checked', false);
										grid.getStore().removeAt(rowIndex);
									}                
								}]
							}]
					},{
						region: 'south',
						title: '选择需要备份的服',
						xtype: 'fieldset',
						items: [{
							xtype: 'button',
							id:'frg_bak_task_button',
							width: 80,
							height: 30,
							text: '发 布 任 务',
							handler: function(){
                                if(Ext.getCmp('FRG_confirm_BAK').getStore().getRange().length > 0){
                                    Ext.MessageBox.show({
                                        id:'frg_bak_new_task_messagebox',
                                        title: '确定发布备份任务吗？',
                                        msg: '发布备份任务前请确定游戏服处关服状态',
                                        width:300,
                                        buttons: Ext.MessageBox.OKCANCEL,
                                        icon:Ext.MessageBox.WARNING,
                                        animateTarget: Ext.getCmp('frg_bak_task_button'),
                                        fn:function(btn){
                                            if(btn=='ok'){
                                                Ext.MessageBox.show({
                                                    id:'frg_bak_new_task_progressbar',
                                                    title: 'Please wait',
                                                    msg: '备份任务发布中...',
                                                    progressText: 'Initializing...',
                                                    width:300,
                                                    progress:true,
                                                    closable:false,
                                                    animateTarget: Ext.getCmp('frg_bak_new_task_messagebox')
                                                });
                                                var task = new Array();
                                                Ext.MessageBox.updateProgress(0.2, '20% completed');
                                                Ext.each(Ext.getCmp('FRG_confirm_BAK').getStore().getRange(), function(childNode){
                                                    task.push({'id':childNode.get('id'),'lang':childNode.get('lang'),'partner':childNode.get('partner'),'server':childNode.get('server')});
                                                });
                                                Ext.MessageBox.updateProgress(0.4, '40% completed');
                                                Ext.Ajax.request({
                                                    url: '/interface.php',
                                                    params: {
                                                        type:'frg_bak_newtask',
                                                        taskid:Ext.encode(task)
                                                    },
                                                    success: function(response){
                                                        if (response.responseText == 'success'){
                                                            Ext.MessageBox.updateProgress(1, '100% completed');
                                                            Ext.MessageBox.hide();
                                                            Ext.getCmp('frgbak_new').close();
                                                            Ext.getStore('FRG_BAK_Store').load();
                                                        }
                                                    }
                                                });
                                            }
                                        }
                                    });
                                }else{
                                    Ext.Msg.alert('警告', '请选择至少一个服！！');
                                }
							}
						}]
					}]
				}]
			});
		}
		frgbak_new.show();
		return frgbak_new;
	},
	generateid:function(rec){
		return 'frgbak_progressbar'+rec.data.id;
	},
	updateProgressBar:function(){
		Ext.TaskManager.start({
			run: function(){
				var old_status = new Object();
				Ext.each(Ext.getStore('FRG_BAK_Store').getRange(), function(childNode){
					old_status[childNode.get('id')]=childNode.get('status');
				});
				Ext.Ajax.request({
					url: '/interface.php',
					params: {
						type: 'frg_bak_progressbar',
						myself:Ext.getStore('FRG_BAK_Store').proxy.extraParams.myself,
						today:Ext.getStore('FRG_BAK_Store').proxy.extraParams.today,
						frgbaktype:Ext.getStore('FRG_BAK_Store').proxy.extraParams.frgbaktype,
						status:Ext.getStore('FRG_BAK_Store').proxy.extraParams.status
					},
					success: function(response){
						var new_status = Ext.JSON.decode(response.responseText);
						for (var tmp in new_status){
							if (new_status[tmp] != old_status[tmp]){
								if ((new_status[tmp] == '2')&&(Ext.getCmp('frgbak_progressbar'+tmp).value != 0.05)){
									Ext.getCmp('frgbak_progressbar'+tmp).updateProgress(0.05,'进程开始...',true);
								}else if ((new_status[tmp] == '3')&&(Ext.getCmp('frgbak_progressbar'+tmp).value != 0.1)){
									Ext.getCmp('frgbak_progressbar'+tmp).updateProgress(0.1,'数据库导出...',true);
								}else if ((new_status[tmp] == '4')&&(Ext.getCmp('frgbak_progressbar'+tmp).value != 0.4)){
									Ext.getCmp('frgbak_progressbar'+tmp).updateProgress(0.4,'备份文件压缩...',true);
								}else if ((new_status[tmp] == '5')&&(Ext.getCmp('frgbak_progressbar'+tmp).value != 0.7)){
									Ext.getCmp('frgbak_progressbar'+tmp).addCls('transport_progress-bar');
									Ext.getCmp('frgbak_progressbar'+tmp).updateProgress(0.7,'备份文件传输...',true);
								}else if ((new_status[tmp] == '6')&&(Ext.getCmp('frgbak_progressbar'+tmp).value != 1)){
									Ext.getCmp('frgbak_progressbar'+tmp).addCls('finish_progress-bar');
									Ext.getCmp('frgbak_progressbar'+tmp).updateProgress(1,'备份完毕！！',true);
								}else if (new_status[tmp] == '255'){
									Ext.getCmp('frgbak_progressbar'+tmp).addCls('error_progress-bar');
									Ext.getCmp('frgbak_progressbar'+tmp).updateProgress(1,'备份错误！！',true);
								}
							}
						}
					}
				});
			},
			interval: 5000
		});		
	}
});